<?php
declare(strict_types=1);
namespace Service\Code;

class CodeBuilder
{
    /**
     * 构建订单号
     * @param int $mn_sid
     * @param string $type
     * @return string
     */
    public static function getCode(int $mn_sid,string $type = '') 
    {        
        return $type.date('YmdHis').$mn_sid. self::generateRandomString(4);
    }
    
    public static function generateRandomString( $length ) 
    {
        $characters         = '0123456789';
        $charactersLength   = strlen($characters);
        $randomString       = '';
        for ($i = 0; $i < $length; $i++) {
            $randomString .= $characters[rand(0, $charactersLength - 1)];
        }
        return $randomString;
    }
}